package com.etc.controller;

import com.etc.pojo.Favorite;
import com.etc.pojo.User;
import com.etc.pojo.Video;
import com.etc.service.FavoriteOfService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/FavoriteOfController")
public class FavoriteOfController {

    Logger logger= Logger.getLogger(FavoriteOfController.class);

    @Autowired
    FavoriteOfService service;


    @RequestMapping("/joinExercise")
    @ResponseBody
    public boolean joinExercise(String userId,Integer videoId){

        User user = new User(userId);
        Video video = new Video(videoId);
        Favorite favorite = new Favorite(0, user, video, null);
        return service.addFavorite(favorite);

    }

    @RequestMapping("/checkFavorite")
    @ResponseBody
    public boolean checkFavorite(String userId,Integer videoId){
        return service.getFavoriteByVideoIdAndUserId(userId,videoId);
    }

    @RequestMapping("/exitExercise")
    @ResponseBody
    public boolean exitExercise(String userId,Integer videoId){
        return service.deleteFavoriteByVideoIdAndUserId(userId,videoId);
    }

}
